package com.example.demo.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;

import java.util.Optional;
//车辆实体
@Data
@TableName("vehicle")
public class Vehicle {
    @TableId(type= IdType.AUTO)
    private Long id;
    @TableField("licence_plate")
    private String licencePlate;//车牌号
    private String piUrl;//车辆入场照片存储位置
    @TableField("parking_lot_id")
    private ParkingLot parkingLot;//关联的停车场
    @TableField("is_active")
    private boolean isActive;//入场，离场标记，true:入场否则离场

    public Vehicle(){
        this.isActive=true;
    }
    public Vehicle(Vehicle entity){
        this.id=entity.id;
        this.isActive=entity.isActive;
        this.piUrl=entity.piUrl;
        this.licencePlate=entity.licencePlate;

//        if(entity.parkingLot!=null){
//            this.parkingLot.setId(entity.parkingLot.getId());
//            this.parkingLot.setName(entity.parkingLot.getName());
//            this.parkingLot.setVolumetric(entity.parkingLot.getVolumetric());
//        }
        Optional.ofNullable(entity.parkingLot)
                .ifPresent(x->{
                    this.parkingLot=new ParkingLot();
                    this.parkingLot.setId(x.getId());
                    this.parkingLot.setName(x.getName());
                    this.parkingLot.setVolumetric(x.getVolumetric());
                });
    }

}